home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / c / ulog / RCS / Ulog_RecordLogin.c,v < prev    next >
Encoding:
Text File  |  1992-04-22  |  5.5 KB  |  253 lines

  1. head     1.6;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.6
  10. date     92.04.21.17.34.28;  author kupfer;  state Exp;
  11. branches ;
  12. next     1.5;
  13.  
  14. 1.5
  15. date     89.01.02.13.54.17;  author douglis;  state Exp;
  16. branches ;
  17. next     1.4;
  18.  
  19. 1.4
  20. date     88.09.22.22.14.38;  author douglis;  state Exp;
  21. branches ;
  22. next     1.3;
  23.  
  24. 1.3
  25. date     88.09.15.10.17.08;  author douglis;  state Exp;
  26. branches ;
  27. next     1.2;
  28.  
  29. 1.2
  30. date     88.09.13.16.44.35;  author douglis;  state Exp;
  31. branches ;
  32. next     1.1;
  33.  
  34. 1.1
  35. date     88.08.14.15.12.04;  author douglis;  state Exp;
  36. branches ;
  37. next     ;
  38.  
  39.  
  40. desc
  41. @Record information that someone is logged in, in the per-host and
  42. per-person database files.
  43. @
  44.  
  45.  
  46. 1.6
  47. log
  48. @Include the remote site in the syslog message when the number of ulog
  49. slots for the host is exceeded.
  50. @
  51. text
  52. @/* 
  53.  * Ulog_RecordLogin.c --
  54.  *
  55.  *    Source code for the Ulog_RecordLogin procedure.
  56.  *
  57.  * Copyright 1988 Regents of the University of California
  58.  * Permission to use, copy, modify, and distribute this
  59.  * software and its documentation for any purpose and without
  60.  * fee is hereby granted, provided that the above copyright
  61.  * notice appear in all copies.  The University of California
  62.  * makes no representations about the suitability of this
  63.  * software for any purpose.  It is provided "as is" without
  64.  * express or implied warranty.
  65.  */
  66.  
  67. #ifndef lint
  68. static char rcsid[] = "$Header: /sprite/src/lib/c/ulog/RCS/Ulog_RecordLogin.c,v 1.5 89/01/02 13:54:17 douglis Exp Locker: kupfer $ SPRITE (Berkeley)";
  69. #endif not lint
  70.  
  71.  
  72. #include <ulog.h>
  73. #include "ulogInt.h"
  74.  
  75.  
  76. /*
  77.  *----------------------------------------------------------------------
  78.  *
  79.  * Ulog_RecordLogin --
  80.  *
  81.  *    Record information for a user in the database.
  82.  *
  83.  * Results:
  84.  *    -1 indicates an error, in which case errno indicates more details.
  85.  *    0 indicates success.
  86.  *
  87.  * Side effects:
  88.  *    The database file is updated.
  89.  *
  90.  *----------------------------------------------------------------------
  91.  */
  92.  
  93. int
  94. Ulog_RecordLogin(uid, location, portID)
  95.     int uid;        /* user identifier */
  96.     char *location;    /* string identifying user's location (host
  97.                or "terminal") */
  98.     int portID;        /* index into host's area in file*/
  99. {
  100.     struct timeval time;
  101.     int status;
  102.     char myHostName[ULOG_LOC_LENGTH];
  103.     char buffer[ULOG_RECORD_LENGTH];
  104.     Host_Entry *hostPtr;
  105.  
  106.  
  107.     if (portID >= ULOG_MAX_PORTS) {
  108.     syslog(LOG_WARNING,
  109.            "Unable to record login from %s for uid %d, port %d: maximum number of entries exceeded.",
  110.            location, uid, portID);
  111.     errno = EINVAL;
  112.     return(-1);
  113.     }
  114.     if (portID < 0) {
  115.     syslog(LOG_ERR, "Invalid port for recording login: %d\n", portID);
  116.     errno = EINVAL;
  117.     return(-1);
  118.     }
  119.     if (strlen(location) >= ULOG_LOC_LENGTH) {
  120.     syslog(LOG_ERR, "Ulog_RecordLogin: location name (%s) too large.",
  121.            location);
  122.     errno = EINVAL;
  123.     return(-1);
  124.     }
  125. #ifdef DEBUG
  126.     syslog(LOG_INFO, "Recording login for uid %d, port %d.", uid, portID);
  127. #endif 
  128.     status = gettimeofday(&time, (struct timezone *) NULL);
  129.     if (status == -1) {
  130.     return(status);
  131.     }
  132.     if (gethostname(myHostName, ULOG_LOC_LENGTH) < 0) {
  133.     syslog(LOG_ERR, "Ulog_RecordLogin: error in gethostname.\n");
  134.     return(-1);
  135.     }
  136.     hostPtr = Host_ByName(myHostName);
  137.     Host_End();
  138.     if (hostPtr == (Host_Entry *) NULL) {
  139.     syslog(LOG_ERR,
  140.            "Ulog_RecordLogin: error in Host_ByName for current host.\n");
  141.     return(-1);
  142.     }
  143.     bzero(buffer, ULOG_RECORD_LENGTH);
  144.     (void) sprintf(buffer, ULOG_FORMAT_STRING, uid, hostPtr->id, portID,
  145.              time.tv_sec, location);
  146.  
  147.     status = Db_WriteEntry(ULOG_FILE_NAME, buffer, 
  148.                hostPtr->id * ULOG_MAX_PORTS + portID,
  149.                ULOG_RECORD_LENGTH, DB_LOCK_BREAK);
  150.     if (status != 0) {
  151.     return(status);
  152.     }
  153.     status = Db_WriteEntry(LASTLOG_FILE_NAME, buffer, uid, ULOG_RECORD_LENGTH,
  154.                DB_LOCK_BREAK);
  155.     return(status);
  156. }
  157. @
  158.  
  159.  
  160. 1.5
  161. log
  162. @added call to Host_End.
  163. @
  164. text
  165. @d17 1
  166. a17 1
  167. static char rcsid[] = "$Header: Ulog_RecordLogin.c,v 1.4 88/09/22 22:14:38 douglis Exp $ SPRITE (Berkeley)";
  168. d58 2
  169. a59 2
  170.            "Unable to record login for uid %d, port %d: maximum number of entries exceeded.",
  171.            uid, portID);
  172. @
  173.  
  174.  
  175. 1.4
  176. log
  177. @changed order of args to DB_*Entry routines.
  178. @
  179. text
  180. @d17 1
  181. a17 1
  182. static char rcsid[] = "$Header: Ulog_RecordLogin.c,v 1.3 88/09/15 10:17:08 douglis Exp $ SPRITE (Berkeley)";
  183. d86 1
  184. @
  185.  
  186.  
  187. 1.3
  188. log
  189. @fixed bug using uninitialized structure for hostID instead of taking
  190. it from hostPtr.
  191. @
  192. text
  193. @d17 1
  194. a17 1
  195. static char rcsid[] = "$Header: Ulog_RecordLogin.c,v 1.2 88/09/13 16:44:35 douglis Exp $ SPRITE (Berkeley)";
  196. d95 1
  197. a95 1
  198.     status = Db_WriteEntry(ULOG_FILE_NAME,
  199. d97 1
  200. a97 1
  201.                ULOG_RECORD_LENGTH, buffer, DB_LOCK_BREAK);
  202. d101 1
  203. a101 1
  204.     status = Db_WriteEntry(LASTLOG_FILE_NAME, uid, ULOG_RECORD_LENGTH, buffer,
  205. @
  206.  
  207.  
  208. 1.2
  209. log
  210. @changed to use ascii representation in database file.
  211. @
  212. text
  213. @d17 1
  214. a17 1
  215. static char rcsid[] = "$Header: Ulog_RecordLogin.c,v 1.1 88/08/14 15:12:04 douglis Exp $ SPRITE (Berkeley)";
  216. a48 1
  217.     Ulog_Data data;
  218. d96 1
  219. a96 1
  220.                data.hostID * ULOG_MAX_PORTS + portID,
  221. @
  222.  
  223.  
  224. 1.1
  225. log
  226. @Initial revision
  227. @
  228. text
  229. @d17 1
  230. a17 1
  231. static char rcsid[] = "$Header: proto.c,v 1.2 88/03/11 08:39:08 ouster Exp $ SPRITE (Berkeley)";
  232. d53 1
  233. d69 6
  234. a77 2
  235.     data.uid = uid;
  236.     data.portID = portID;
  237. a81 4
  238.     data.updated = time.tv_sec;
  239.     (void) strncpy(data.location, location, ULOG_LOC_LENGTH - 1);
  240.     data.location[ULOG_LOC_LENGTH] = '\0';
  241.  
  242. d92 3
  243. a94 1
  244.     data.hostID = hostPtr->id;
  245. d98 1
  246. a98 1
  247.                sizeof(data), (char *) &data, DB_LOCK_BREAK);
  248. d102 2
  249. a103 2
  250.     status = Db_WriteEntry(LASTLOG_FILE_NAME, uid, sizeof(data),
  251.                (char *) &data, DB_LOCK_BREAK);
  252. @
  253.